#include <list>
#include <time.h>
#include <math.h>

using namespace std;

class Structures {
public:
	struct process {
		process(int p, long b, long m): pid(p), burst(b), memoryReq(m){}
		int pid;
		long burst;     // in mega cycles
		long memoryReq; // in KB
	};
	
	struct processor {
		processor(char c, int m, int s): processorid(c), memory(m), speed(s){}
		char processorid;     // processor ID
		int executingPid;     // pid of currently executing process
		int memory;           // in KB
		int speed;            // in MHz
		double timeLeft;       // remaining time to complete all scheduled processes
		long cyclesRemaining; // remaining number of cycles in all scheduled processes
		long memoryLeft;      // in MB
		list<process> processes;
	};

	// process comparison
	static bool compareProcessCycles(process first, process second){
		if (first.burst < second.burst)
			return true;
		else
			return false;
	}

	// process comparison, sort by memoryReq descending, then burst ascending
	static bool compareProcessMem(process first, process second){
		if (first.memoryReq > second.memoryReq)
			return true;
		else if (first.memoryReq == second.memoryReq) //memory equal, sort by burst
		{
			if (first.burst < second.burst)
				return true;
			else
				return false;
		}
		else
			return false;
	}

	// processor comparison
	static bool compareProcessorCycles (processor first, processor second){
		if (first.cyclesRemaining < second.cyclesRemaining)
			return true;
		else
			return false;
	}

	// processor comparison
	static bool compareProcessorTime (processor first, processor second){
		if (first.timeLeft < second.timeLeft)
			return true;
		else
			return false;
	}
	
	// sort processors by char ID
	static bool compareProcessorID (processor first, processor second){
		if (first.processorid < second.processorid)
			return true;
		else
			return false;
	}

	// generates a list of processes
	static list<process> generateProcesses(int num){
		list<process> tempList;
	
		srand((unsigned int)time(NULL));

		for(int i = 0; i < num; i++){
			// burst time between 10 and 50000000 mega-cycles, memory between .25 MB and 8192 MB
			tempList.push_back(*(new process(i, (rand() % 49999990) + 10, (256 * (long)pow(2.0, (rand() % 16))))));
		}

		return tempList;
	}
};